<%content_for :head do%>
    <link rel="stylesheet" type="text/css" href="/stylesheets/ui.dropdownchecklist.css" /> 
    <script type="text/javascript" src="/javascripts/ui.core-min.js"></script> 
    <script type="text/javascript" src="/javascripts/ui.dropdownchecklist-min.js"></script> 

<script type="text/javascript">
	
	jQuery.noConflict();
	
	jQuery(document).ready(function(){ 
		jQuery("#Site").dropdownchecklist({ width: 800, maxDropHeight: 150 });
		jQuery("#Strategy").dropdownchecklist({width: 800, maxDropHeight: 100 });
		<% if action_type == "edit"%>
			document.getElementById('pass_div').style.display = "none";
		<% end %>
	 });

  function enable_disable_pass(el){
  	if(el) {
		jQuery('#pass_div').css("display","block");
  	}
  	else {
		jQuery('#pass_div').css("display","none");
		jQuery('#user_password').val ="";
		jQuery('#user_password_confirmation').val ="";
  	}
  }
</script>

<%end%>
<%	if f.object.errors.count > 1 then
		header_msg =  " #{f.object.errors.count} errors prevented this user from being saved"
  	else
		header_msg =  " #{f.object.errors.count} error prevented this user from being saved"
	end			
 %>



<%= f.error_messages :header_message => header_msg %> 
	
<div id="top_buttons">
       
        </div><!--/top_buttons-->

		<div id="mainreports">
			 
			 <p>  <%= f.label :name %><br />  <%= f.text_field :name %>  </p> 
			 <p>  <%= f.label :login %><br />  <%= f.text_field :login %>  </p>
			 <p>  <%= f.label :email %><br />  <%= f.text_field :email %>  </p> 
			 
			  <p>
			 <%if action_type=="edit" %>
			 	<%= label_tag _('Change Password') %>
				<%= check_box_tag 'change_password', 'change password', false ,:onchange => "enable_disable_pass(change_password.checked);" %>
			 <%end%>
			  </p>
			 <div id="pass_div">
			 <p>  <%= f.label :password, _("Password")%><br />  <%= f.password_field :password,  :autocomplete => :off %>  </p> 			 
			 <p>  <%= f.label :password_confirmation, _("Password confirmation") %><br />  <%= f.password_field :password_confirmation,  :autocomplete => :off %>  </p>
             </div>
			 <p>  <%= f.label :phone %><br />  <%= f.text_field :phone %>  </p> 
			 <p>  <%= f.label :country %><br />  <%= f.select ("country_id", Country.find(:all, :order=>"name").map {|c| [_(c.name), c.id]}) %>  </p> 
			 <p>  <%= f.label :city %><br />  <%= f.text_field :city %>  </p> 
			  <p>  <%= f.label :preferred_language %><br />  <%= f.select ("preferred_language", LANGUAGES.map{|x| [x["name"], x["locale"]]}) %>  </p> 
			 
			 <div class="line_one"></div>
			 
			 <div class="title_two"><%= _('Role')%> <%=_("(Please select one or more of the following of this account fulfills this role)") %></div>
		
		<ul>
		<% Role.types.each {|type|
			role = user.get_role(type) || Role.new(:users => [user], :coordinated_type => type.to_s)
			role.instance_variable_set(:@enabled, !role.id.blank?) %>
				<li>  
				<p>
				<%= Role.description(type) %> 
				<% multiple=true %>
				<% options_map=Array.new %>
				<%  types=type.all %>
				<% if type==Country.name.constantize %>
					<% options_map+=[[_("none"),-1]] %>
					<%  types=types.delete_if {|x| x.name == _("Other")}  %>
					<%  types=types.sort { |t1, t2| t1.name <=> t2.name }  %>
					<% multiple=false %>
				<% end %>
				<% if type==Site.name.constantize %>
					<%  types=types.sort { |t1, t2| [t1.country.name,t1.name] <=> [t2.country.name,t2.name] }  %>
				<% end %>
				<% options_map+=types.map {|s| [_(s.description), s.id]} %>
				<% if not roles_map.nil? %>
					<% if not roles_map[type.name].nil? %>
						<% selected=Array.new %>
						<% roles_map[type.name].each { |value| %>
							<% if value.instance_of? String
 								value=value.to_i
							end %>	
							<% selected.push(value)%>
						<% } %>	
					<% end %>	
				<% end %>
				<div><%= select_tag type, options_for_select(options_map, selected) , :multiple => multiple %></div>
				<p/>
				</li>
		<% }%>
		</ul>
  
	<div class="line_one"></div>
 
 	<div class="title_two"><%= _('Permissions') %></div>  
	
	<p>   <%= f.check_box :is_admin %>   <%= f.label :user_is_an_administrator_of_this_site, _("User is an administrator of this site")  %> </p> 
	<p>   <%= f.check_box :allow_login %>   <%= f.label :allow_this_user_to_login, _("Allow this user to login")  %> </p> 
</div>

 
<%= image_submit_tag "b_save.gif" %>
<%= link_to image_tag("b_cancel.gif"), :action => 'index'%>
 




